package com.wsc.wisdomchinaqinghe.activitity.fourmodule;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wsc.wisdomchinaqinghe.R;
import com.wsc.wisdomchinaqinghe.Tools.JsonTools;
import com.wsc.wisdomchinaqinghe.Tools.Tools;
import com.wsc.wisdomchinaqinghe.activitity.baseactivity.BaseActivity;
import com.wsc.wisdomchinaqinghe.adapter.PeopleControlDetailAdapter;
import com.wsc.wisdomchinaqinghe.callback.ContributorView;
import com.wsc.wisdomchinaqinghe.javaBean.FeedBackDetailBean;
import com.wsc.wisdomchinaqinghe.javaBean.RespObj;
import com.wsc.wisdomchinaqinghe.presenter.ContributorPresenter;
import com.wsc.wisdomchinaqinghe.view.MyListView;

/**
 * 百姓监督详情页面
 * Created by ${wangtao} on 2017/3/10.
 */

public class PeopleControlDetailActivity extends BaseActivity implements View.OnClickListener,ContributorView{


    private TextView fragment_bxjdxq_title;//标题
    private TextView fragment_bxjdxq_name;//姓名
    private TextView fragment_bxjdxq_time;//时间
    private TextView fragment_bxjdxq_person;//关注人数
    private TextView fragment_bxjdxq_content;//内容
    private LinearLayout fragment_bxjdxq_back;//返回按钮
    private MyListView fragment_bxjdxq_listView;//列表
    private ContributorPresenter contributorPresenter;
    private Context context;
    private final String PEOPLECONTROL_FLAG="PEOPLECONTROL_FLAG";
    private TextView tv_remark;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.peoplecontroldetail_layout);
        initView();
        context=this;
        contributorPresenter=new ContributorPresenter(this,context);
        String id=getIntent().getStringExtra("id");
        contributorPresenter.getFeedBackDetail(id,PEOPLECONTROL_FLAG);
    }

    private void initView()
    {
        fragment_bxjdxq_title=(TextView) findViewById(R.id.fragment_bxjdxq_title);//标题
        fragment_bxjdxq_name=(TextView) findViewById(R.id.fragment_bxjdxq_name);//姓名
        fragment_bxjdxq_time=(TextView) findViewById(R.id.fragment_bxjdxq_time);//时间
        fragment_bxjdxq_person=(TextView) findViewById(R.id.fragment_bxjdxq_person);//关注人数
        fragment_bxjdxq_content=(TextView) findViewById(R.id.fragment_bxjdxq_content);//内容
        fragment_bxjdxq_back=(LinearLayout) findViewById(R.id.fragment_bxjdxq_back);//返回按钮
        fragment_bxjdxq_listView=(MyListView) findViewById(R.id.fragment_bxjdxq_listView);//列表
        fragment_bxjdxq_back.setOnClickListener(this);
        tv_remark=(TextView) findViewById(R.id.tv_remark);
        fragment_bxjdxq_title.requestFocus();
        fragment_bxjdxq_title.setFocusable(true);
        fragment_bxjdxq_title.setFocusableInTouchMode(true);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.fragment_bxjdxq_back:
                finish();
                break;
        }
    }
    @Override
    public void onLoadContributorStart(String flag) {

    }


    @Override
    public void onLoadContributorSuccess(String jsonString, String flag) {
        try {
            if (flag.equals(PEOPLECONTROL_FLAG)) {
                RespObj respObj = JsonTools.jsonStringToObject(jsonString, RespObj.class);
                String code = respObj.getCode();
                Object object = respObj.getMessage();
                if (code.equals("200") && object != null) {
                    String jsonMessage = JsonTools.objectToJsonString(object);
                    FeedBackDetailBean feedBackDetailBean = JsonTools.jsonStringToObject(jsonMessage, FeedBackDetailBean.class);
                    if (feedBackDetailBean != null) {
                        fragment_bxjdxq_title.setText(feedBackDetailBean.getTitle());
                        fragment_bxjdxq_name.setText(feedBackDetailBean.getReleaseName());
                        fragment_bxjdxq_person.setText(String.valueOf(feedBackDetailBean.getSeeCount()));
                        fragment_bxjdxq_content.setText(feedBackDetailBean.getContent());
                        String date_time = Tools.timesTwo(String.valueOf(feedBackDetailBean.getCrt() / 1000));
                        fragment_bxjdxq_time.setText(date_time);
                        String remark=feedBackDetailBean.getRemark();
                        if(remark!=null && !remark.isEmpty())
                        {
                            tv_remark.setText("处理结果:  "+remark);
                        }
                        PeopleControlDetailAdapter bxjdxqImage_adapter = new PeopleControlDetailAdapter(context, feedBackDetailBean.getBanners());
                        fragment_bxjdxq_listView.setAdapter(bxjdxqImage_adapter);
                    }

                }
            }
        } catch (Exception e) {

        }
    }


    @Override
    public void onLoadContributorComplete(String flag) {
    }

    @Override
    public void onLoadContributorError(String error, String flag) {
    }

}
